{% extends "xadmin/base_site.html" %}
{% load i18n %}
{% load url from future %}
{% load xadmin_tags %}
{% load crispy_forms_tags %}

{% block breadcrumbs %}
{% if account_view %}
<ul class="breadcrumb">
  <link href="/websys/static/xadmin/vendor/bootstrap-table/css/bootstrap-table.min.css" type="text/css" media="screen" rel="stylesheet" />
<li><a href="{% url 'xadmin:index' %}">{% trans 'Home' %}</a></li>
  <li class="active"> {{ title }} </li>
</ul>
{% else %}
<ul class="breadcrumb">
  <li><a href="{% url 'xadmin:index' %}">{% trans 'Home' %}</a></li>
  <li>
    {% if has_view_permission %}
    <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>
    {% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %}
  </li>
  <li><a href="{% url opts|admin_urlname:'change' original.pk %}">{{ original|truncatewords:"18" }}</a></li>
  <li class="active">{% trans 'Change password' %}</li>
</ul>
{% endif %}
{% endblock %}

{% block content-nav %}
{% endblock %}
{% block content %}
<!--页面设计在这儿....{{ serverval }}-->
    <style>
    .tb_tr{height: 50px; border:gainsboro 1px  double;}
    .tb_td{height: 50px; border: gainsboro 1px double; width:80px;}
    .td_info_1{background-color: #1da7ee;color: #0C0C0C;width: 100px;height: 30px; border:gainsboro 1px  double;}
    .td_info_2{width: 150px; border:gainsboro 1px  double;}
    .td_info_3{width: 300px; border:gainsboro 1px  double;}
    .txt_10{width: 200px;}
    .txt_30{width: 300px;}
    .td_title_1{font-weight: bold; font-size: 15px;}
    .tr_card_0{background-color: #1da7ee;}
    .tr_card_0 td{width: 130px;}
    .tb_normal{}
    .tb_normal td{border:gainsboro 1px  double;}
    </style>
    <table id="tb_main" style="width: 100%">
        <tr class="tb_tr">
            <td class="tb_td">服务器：</td>
            <td>
                <select id="sel_pf">
                    <option value="" selected="selected">请选择</option>
                    {% for item in htmldata.apps %}
                            <option value="{{ item.pf }}">{{ item.name }}</option>
                    {% endfor %}
                </select>
            </td>
        </tr>
        <tr class="tb_tr" id="tr_nickname" >
            <td class="tb_td">玩家昵称：</td>
            <td><input type="text" maxlength="40" id="txt_nickname" class="txt_30"><span>注:此项可忽略不填,如昵称查询服务器必选!</span></td>
        </tr>
        <tr class="tb_tr" id="tr_uid" >
            <td class="tb_td">Uid：</td>
            <td><input type="text" maxlength="40" id="txt_uid" class="txt_30"><span>注:此项可忽略不填,UID查询可忽略服务器!</span></td>
        </tr>
        <tr class="tb_tr">
            <td class="tb_td"></td>
            <td><label id="la_link"> {{links}}</label>&nbsp;&nbsp;<input type="button" id="bt_copy" value="查询" onclick="toSearch()"><span>注:如有昵称、UID,请优先UID查询!</span></td>
        </tr>
        <tr class="tb_tr">
            <td class="tb_td td_title_1">状态信息：</td>
            <td></td>
         </tr>
        <tr>
        <td class="tb_td"></td>
            <td>
                <table id="tb_info">
                    <tr>
                        <td class="td_info_1">玩家UID</td>
                        <td class="td_info_3"><label id="la_uid"></label> </td>
                    </tr>
                    <tr>
                        <td class="td_info_1">玩家昵称</td>
                        <td class="td_info_3"><label id="la_nick"></label> </td>
                    </tr>
                    <tr>
                        <td class="td_info_1">玩家账号</td>
                        <td class="td_info_3"><label id="la_account"></label> </td>
                    </tr>
                    <tr>
                        <td class="td_info_1">充值金额</td>
                        <td class="td_info_3"><label id="la_recharge_money"></label> </td>
                    </tr>
                    <tr>
                        <td class="td_info_1">VIP</td>
                        <td class="td_info_3"><label id="la_VIP"></label> </td>
                    </tr>
<!--                     <tr>
                        <td class="td_info_1">是否在线</td>
                        <td ><label id="la_isonlie"></label> </td>
                    </tr> -->
                    <tr>
                        <td class="td_info_1">注册时间</td>
                        <td class="td_info_3"><label id="la_retime"></label> </td>
                    </tr>
<!--                     <tr>
                        <td class="td_info_1">注册IP</td>
                        <td ><label id="la_reip"></label> </td>
                    </tr> -->
                    <tr>
                        <td class="td_info_1">服务器</td>
                        <td class="td_info_3"><label id="la_server"></label> </td>
                    </tr>
                    <tr>
                        <td class="td_info_1">等级</td>
                        <td class="td_info_3"><label id="la_level"></label> </td>
                    </tr>
<!--                     <tr>
                        <td class="td_info_1">战斗力</td>
                        <td ><label id="la_create_time"></label> </td>
                        <td class="td_info_1">竞技场排行</td>
                        <td ><label id="la_role_ip"></label> </td>
                    </tr>
                    <tr>
                        <td class="td_info_1">充值金额</td>
                        <td ><label id="la_recharge_money"></label> </td>
                        <td class="td_info_1">充值次数</td>
                        <td ><label id="la_recharge_num"></label> </td>
                    </tr> -->
                </table>
            </td>
        </tr>

<!--          <tr class="tb_tr">
            <td class="tb_td td_title_1">卡牌信息：</td>
            <td></td>
         </tr>
        <tr>
        <td class="tb_td"></td>
            <td>
                <table id="tb_cards" class="tb_normal">
                    <tr class="tr_card_0">
                        <td>卡牌名称</td>
                        <td>卡牌id</td>
                        <td>卡牌等级</td>
                        <td>卡牌阶数</td>
                        td>卡牌位置</td
                    </tr>
                </table>
            </td>
        </tr> --> 

        <tr class="tb_tr">
            <td class="tb_td td_title_1">背包物品：</td>
            <td></td>
         </tr>
        <tr>
        <td class="tb_td"></td>
            <td>
                <table id="tb_props" class="tb_normal">
                    <tr class="tr_card_0">
                        <td>道具id</td>
                        <td>道具名称</td>
                        <td>道具数量</td>
                    </tr>
                </table>
            </td>
        </tr>

        <tr class="tb_tr">
            <td class="tb_td td_title_1">英雄：</td>
            <td></td>
         </tr>
        <tr>
        <td class="tb_td"></td>
            <td>
                <table id="tb_hero" class="tb_normal">
                    <tr class="tr_card_0">
                        <td>英雄id</td>
                        <td>名称</td>
                        <td>等级</td>
                        <td>数量</td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr class="tb_tr">
            <td class="tb_td td_title_1">装备：</td>
            <td></td>
         </tr>
        <tr>
        <td class="tb_td"></td>
            <td>
                <table id="tb_equipment" class="tb_normal">
                    <tr class="tr_card_0">
                        <td>装备id</td>
                        <td>名称</td>
                        <td>等级</td>
                        <td>数量</td>
                    </tr>
                </table>
            </td>
        </tr>

<!--         <tr class="tb_tr">
            <td class="tb_td td_title_1">任务信息：</td>
            <td></td>
         </tr>
        <tr>
        <td class="tb_td"></td>
            <td>
                <table id="tb_tasks" class="tb_normal">
                    <tr class="tr_card_0">
                        <td>任务名称</td>
                        <td>任务id</td>
                    </tr>
                </table>
            </td>
        </tr> -->

    </table>
    <script>
    //重置数据，查询前清了旧数据
    function resetData()
    {
        if( $('#hid_uid').val()!='')
        {
            //清除labal
            $("#tb_main label").each(function(i){
                if(this.id.indexOf('la_')==0) {
                    //alert(this.id);
                    this.innerHTML = "";
                }
             });
            // //清除txt
            // $("#tb_main input[type='text']").each(function(i){
            //     if(this.id.indexOf('_uid')<1) {
            //         //alert(this.id);
            //         this.value = "";
            //     }
            //  });
            //删除表格
            delTable('tb_props');
            delTable('tb_hero');
            delTable('tb_equipment');
        }
    }
    //查询


    function toSearch()
    {   
        var pf = $('#sel_pf').val();
        var nickname=$('#txt_nickname').val();
        var uid =$('#txt_uid').val();
        if(nickname!=''){
        if(pf=='')
        {
            alert('请选服务器!');
            return;
        }
        }
        if(nickname==''&&uid=='')
        {
            alert('昵称和UID不能都为空!');
            return;
        }
        if(nickname!=''&&uid!='')
        {
            alert('请忽略昵称,优先UID查询!');
            return;
        }
        resetData();

        getData(pf,nickname,uid);

    }
    //显示 某个玩家的数据
    function getData(pf,nickname,uid)
    {

        $.post('/xadmin/ajax_cbyx_userdata/getuser', {"nickname":nickname,"server":pf,'uid':uid}, function(result){
            //alert(result.code);return;
			if(result.code == 0)
			{
				showData(result);
                //有数据就设置，以备修改时用
                //$('#hid_uid').val(_uid+','+nickname);
			}else
			{
				alert('查询失败(用户不存在或输入错误!),请重新查询:'+result.code);
			}
		 }, "json");


    }
    function showData(jsonObj)
    {
        //用户属性
        for (var prop in jsonObj.user_info)
        {
          //alert("jsonObj.userInfo[" + prop + "]=" + jsonObj.userInfo[prop]);
            if ($("#la_"+prop).length > 0) {
                $("#la_"+prop).html(jsonObj.user_info[prop]);
            }
        }
        // //卡牌
        // addTR_Cards(jsonObj.cards);
        //背包
        addTR_Props(jsonObj.bag);
        addTR_hero(jsonObj.hero);
        addTR_equipment(jsonObj.equipment);

    }
    //保存某个属性
   //  function save_data(obj)
   //  {
   //      alert(obj.id);

   //      var tmp_arr=obj.id.split('_');
   //      var t_key=tmp_arr[1];
   //      var t_val=$('#txt_'+t_key).val();

   //      if(t_val=='')
   //      {
   //          alert('请输入数值');
   //          return;
   //      }

   //      var tmp_val=$('#hid_uid').val();
   //      if(tmp_val=='')
   //      {
   //          alert('请先查询正确的玩家');
   //          return;
   //      }
   //      tmp_arr=tmp_val.split(',');
   //      var _uid=tmp_arr[0];
   //      var _sid=tmp_arr[1];
   //      $.post('/xadmin/ajax_cbyx_userdata/saveuser', {"uid":_uid, "sid":_sid,"key":t_key, "value":t_val}, function(result){
   //          //alert(result.code);return;
			// if(result.code == 0)
			// {
			// 	$('#la_'+t_key).innerHTML(t_val);
			// }else
			// {
			// 	alert('修改失败:'+result.code);
			// }
		 // }, "json");
   //  }
    // //是否有地址栏参数?uid=xxx&sid=xxx
    // function getQueryString(){
    //      result = {}
    //      r = new RegExp("[\?\&]([^\?\&]+)=([^\?\&]+)","g")
    //      a = r.exec(location.href)
    //      while(a)
    //     {    console.log(a)
    //          result[a[1]]=a[2]
    //           a = r.exec(location.href)
    //     }
    //      return result;

    // }
    // function initData()
    // {
    //     var t_uid='',t_sid='';
    //     var t_obj=getQueryString();
    //     for(var ii_key in t_obj) {
    //         if (ii_key=='uid')
    //         {
    //             t_uid=t_obj[ii_key];
    //         }
    //         else if (ii_key=='sid')
    //         {
    //             t_sid=t_obj[ii_key];
    //         }
    //     }
    //     if(t_uid!='' && t_sid!='')
    //     {
    //         $('#txt_uid').val(t_uid);
    //         $('#sel_pf').val(t_sid);
    //         getData(t_uid,t_sid);
    //     }

    // }
    // $(function() {
    //     initData();
    //     addTR_Props();
    // });
    //动态表格处理
    function delTable(tid)
    {
        //清空主题Table的数据
        var t=document.getElementById(tid);  //获取Table
        var length= t.rows.length;          //获得Table下的行数
        if(length!=0){              //如果有行，则清空
            for(var i=length-1;i>0;i--)
            {
             t.deleteRow(i);
            }
        }
    }
    function addTR_Props(provinces)
    {
        var t=document.getElementById('tb_props');
        for (var i = 0; i < provinces.length; i++) {
            //tr
           var r = t.insertRow(t.rows.length);//创建新的行
            var tr_data=provinces[i];
            //td
            var c = r.insertCell();                //创建新的列
            //c.innerHTML = "<input type='checkbox' name='zhutiIds' value="+provinces[i][0]+">"+provinces[i][1];
            c.innerHTML= tr_data.id;
            c = r.insertCell();
            c.innerHTML= tr_data.name;
            c = r.insertCell();
            c.innerHTML= tr_data.num;
            }
    }
    function addTR_hero(provinces)
    {
        var t=document.getElementById('tb_hero');
        for (var i = 0; i < provinces.length; i++) {
            //tr
           var r = t.insertRow(t.rows.length);//创建新的行
            var tr_data=provinces[i];
            //td
            var c = r.insertCell();                //创建新的列
            //c.innerHTML = "<input type='checkbox' name='zhutiIds' value="+provinces[i][0]+">"+provinces[i][1];
            c.innerHTML= tr_data.id;
            c = r.insertCell();
            c.innerHTML= tr_data.name;
            c = r.insertCell();
            c.innerHTML= tr_data.level;
            c = r.insertCell();
            c.innerHTML=tr_data.num;
            }
    }

    function addTR_equipment(provinces)
    {
        var t=document.getElementById('tb_equipment');
        for (var i = 0; i < provinces.length; i++) {
            //tr
           var r = t.insertRow(t.rows.length);//创建新的行
            var tr_data=provinces[i];
            //td
            var c = r.insertCell();                //创建新的列
            //c.innerHTML = "<input type='checkbox' name='zhutiIds' value="+provinces[i][0]+">"+provinces[i][1];
            c.innerHTML= tr_data.id;
            c = r.insertCell();
            c.innerHTML= tr_data.name;
            c = r.insertCell();
            c.innerHTML= tr_data.level;
            c = r.insertCell();
            c.innerHTML=tr_data.num;
            }
    }
    //[u'lv', u'star', u'id', u'name']
    // function addTR_Cards(provinces)
    // {
    //     //var objmoList1=new Array();//数组
    //     // var objmo=new Object();
    //     // 对象objmo.s="11";//对象里面的属性objmo.t="22";objmoList1.push(objmo);alert(objmoList1[0].s);
    //     //var provinces=new Array({'id':0,'name':'qq','num':1},{'id':2,'name':'mm','num':33});
    //     //var provinces=new Array();
    //     //var objmo={'id':0,'name':'qq','num':1};
    //     //var objmo=new Object();
    //     //objmo.id=0;objmo.name='qq';objmo.num=12;
    //     //provinces.push(objmo);

    //     var t=document.getElementById('tb_cards');
    //     for (var i = 0; i < provinces.length; i++) {
    //         //tr
    //        var r = t.insertRow(t.rows.length);//创建新的行
    //         var tr_data=provinces[i];
    //         //td
    //         var c = r.insertCell();                //创建新的列
    //         //c.innerHTML = "<input type='checkbox' name='zhutiIds' value="+provinces[i][0]+">"+provinces[i][1];
    //         c.innerHTML= tr_data.id;
    //         c = r.insertCell();
    //         c.innerHTML= tr_data.name;
    //         c = r.insertCell();
    //         c.innerHTML= tr_data.lv;
    //         c = r.insertCell();
    //         c.innerHTML= tr_data.star;
    //         }
    // }
    </script>
{% endblock %}